<template>
  <div class="page">
    <div class="content">
      <t-loading v-if="loading"></t-loading>
      <template v-if="info">
        <div class="title">{{ info.title }} </div>
        <div class="date">{{ info.createTime }}</div>

        <div class="main-body">
          <div v-html="info.content"></div>
        </div>
      </template>
    </div>
  </div>
</template>

<script>
import { contentDetail } from "@/api/content";
import TLoading from "@/components/t-loading";

export default {
  name: "index",
  components: { TLoading },
  data() {
    return {
      loading: false,
      info: ''
    }
  },
  watch: {
    '$route'() {
      this.getContentDetail();
    }
  },
  created() {
    this.getContentDetail();
  },
  methods: {
    getContentDetail() {
      this.loading = true;
      let id = this.$route.query.id || this.$route.params.id;
      let code = this.$route.query.code || this.$route.params.code;
      let data = {}
      if(code){
        data.code = code
      }else{
        data.id = id
      }
      contentDetail(data).then((res) => {
        this.loading = false;
        console.log(res.result);
        this.info = res.result;
      }).catch(() => {
        this.loading = false;
      })
    }
  }
}
</script>

<style scoped lang="less">
.page {
  background: #F5F5F5;

  .content {
    box-sizing: border-box;
    width: 840px;
    margin: 40px auto;
    background: #FFFFFF;
    padding: 40px;
  }

  .title {
    display: block;
    color: @t-title-color;
    font-size: 24px;
    font-weight: 500;
  }

  .date {
    margin-top: 6px;
    color: #999999;
    font-size: 14px;
  }

  .main-body {
    margin-top: 40px;
    color: @t-title-color;

    /deep/ img {
      display: block;
      width: 100% !important;
      height: auto !important;
    }
  }
}
</style>